﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using System.Linq;
using System.Windows;
namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {
        public void YCAEKAB15(DataSet db)
        {
            try
            { 
                DataTable dtSoruce = db.Tables["EKPOS"];
                DataTable dtOutput = new DataTable();
                dtOutput.Columns.Add("EKPNEUB", typeof(System.String));
                dtOutput.Columns.Add("ABPART", typeof(System.String));
                dtOutput.Columns.Add("FSABEZ", typeof(System.String));
                dtOutput.Columns.Add("FSARTPRGR", typeof(System.String));
                dtOutput.Columns.Add("ABPFARBE", typeof(System.String));
                dtOutput.Columns.Add("FSFFBEZ", typeof(System.String));
                dtOutput.Columns.Add("FSSZUSCHN", typeof(System.String));
                dtOutput.Columns.Add("ABAART", typeof(System.String));
                dtOutput.Columns.Add("ABAFARBE", typeof(System.String));
                dtOutput.Columns.Add("MTYPE", typeof(System.String));
                dtOutput.Columns.Add("EXART", typeof(System.String));
                dtOutput.Columns.Add("EXCOLOR", typeof(System.String));
                dtOutput.Columns.Add("ABAGROE", typeof(System.String));
                dtOutput.Columns.Add("LSNAME1", typeof(System.String));
                dtOutput.Columns.Add("ABAAUFKRS", typeof(System.String));
                dtOutput.Columns.Add("ABAAUFLFD", typeof(System.String));
                dtOutput.Columns.Add("ABAAUFPOS", typeof(System.String));
                dtOutput.Columns.Add("ABARESMG", typeof(System.Decimal));
                dtOutput.Columns.Add("ABAQTYRESERVE", typeof(System.Decimal));
                dtOutput.Columns.Add("EKPME1", typeof(System.Decimal));
                dtOutput.Columns.Add("EKPME3", typeof(System.Decimal));
                dtOutput.Columns.Add("WAUEBM", typeof(System.String));
                dtOutput.Merge(dtSoruce, false, MissingSchemaAction.Ignore);
                foreach (DataRow row in dtOutput.Rows)
                {
                    if (row["MTYPE"].ToString().Trim() == "T")
                    {
                        row["FSSZUSCHN"] = "辅料";
                        continue;
                    }
                    switch (row["FSSZUSCHN"].ToString().Trim())
                    {
                        case "J":
                            row["FSSZUSCHN"] = "主面料";
                            break;
                        case "C":
                            row["FSSZUSCHN"] = "衬布";
                            break;
                        case "N":
                            row["FSSZUSCHN"] = "配布";
                            break;
                        case "":
                            row["FSSZUSCHN"] = "里布";
                            break;
                    }
                }
                dtOutput.Columns.Remove("MTYPE");
                exAgent.DataTableToExcel(dtOutput, 3, 1);
                int count = dtOutput.Rows.Count;
                exAgent.SetCellValue(1, 1, 1);
                exAgent.BatchConvert2Number(2, 17, count + 1, 20);
                exAgent.SetCellValue(1, 1, "原料采购清单");
                MergeSameFART(count, 2);
                MergeSameFART(count, 3);
                //MergeSameFART(count, 4);
                MergeSameFART(count, 5);
                MergeSameFART(count, 6);
                MergeSameFART(count, 7);
                /*MergeSameFART(count, 8);
                MergeSameFART(count, 9);
                MergeSameFART(count, 10);
                MergeSameFART(count, 11);
                MergeSameFART(count, 12);
                MergeSameFART(count, 13);
                MergeSameFART(count, 14);*/
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void MergeSameFART(int rows, int ystart)
        {
            int x1, y1, x2, y2;
            string str = "";
            string str1;
            int xstart = 3;
            y1 = ystart;
            y2 = ystart;
            x1 = xstart;
            x2 = xstart;
            for (int i = 3; i <= rows + 3; i++)
            {
                str1 = (string)exAgent.GetCellValue(i, ystart);
                if (str == str1)
                {
                    x2 = i;
                }
                else
                {
                    if (x2 > x1)
                    {
                        exAgent.Merge(x1, y1, x2, y2);
                    }
                    x1 = i;
                    str = str1;
                }
            }
        }
    }
}